home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OCFINC.PAK / OCSTORAG.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  9KB  |  267 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectComponents
  3. // Copyright 1994, 1997 by Borland International, All Rights Reserved
  4. //
  5. // $Revision:   2.7  $
  6. //
  7. // Definition of TOcStorage & TOcStream classes
  8. //----------------------------------------------------------------------------
  9. #if !defined(OCF_OCSTORAG_H)
  10. #define OCF_OCSTORAG_H
  11.  
  12. #if !defined(OCF_DEFS_H)
  13. # include <ocf/defs.h>
  14. #endif
  15.  
  16. //
  17. // Classes referenced
  18. //
  19. class _ICLASS IRootStorage;
  20. class _ICLASS IStorage;
  21. class _ICLASS IStream;
  22. class _ICLASS ILockBytes;
  23. class _ICLASS IEnumSTATSTG;
  24.  
  25. #if defined(BI_NAMESPACE)
  26. namespace OCF {
  27. #endif
  28.  
  29. //
  30. // Classes defined
  31. //
  32. class _ICLASS TOcStream;
  33. class _ICLASS TOcStorage;
  34.  
  35. #if defined(BI_NAMESPACE)
  36. } // namespace OCF
  37. #endif
  38.  
  39. //----------------------------------------------------------------------------
  40. // Storage specific definitions & types, primarily for use under Win16
  41. //
  42. #if !defined(HUGE)
  43. # if defined(BI_PLAT_WIN16)
  44. #   define HUGE  __huge
  45. # else
  46. #   define HUGE
  47. # endif
  48. #endif
  49.  
  50. #if !defined(BI_PLAT_WIN32)
  51.  
  52. #if !defined(_COMPOBJ_H_)
  53.   struct far ULARGE_INTEGER {unsigned long LowPart; unsigned long HighPart;};
  54.   struct far  LARGE_INTEGER {unsigned long LowPart;   signed long HighPart;};
  55. #endif
  56.  
  57. typedef char far* far* SNB;
  58.  
  59. #if !defined(_FILETIME_)
  60. # define _FILETIME_
  61.   struct far FILETIME {uint32 dwLowDateTime; uint32 dwHighDateTime;};
  62. #endif
  63.  
  64. #if !defined(_STORAGE_H_)
  65. struct far STATSTG {
  66.   char far* pwcsName;
  67.   uint32    type;
  68.   ULARGE_INTEGER cbSize;
  69.   FILETIME  mtime;
  70.   FILETIME  ctime;
  71.   FILETIME  atime;
  72.   uint32    grfMode;
  73.   uint32    grfLocksSupported;
  74.   IID       clsid;
  75.   uint32    grfStateBits;
  76.   uint32    reserved;
  77. };
  78. #define STATFLAG_NONAME 1
  79.  
  80. #define STGM_DIRECT           0x00000000L
  81. #define STGM_TRANSACTED       0x00010000L
  82. #define STGM_READ             0x00000000L
  83. #define STGM_WRITE            0x00000001L
  84. #define STGM_READWRITE        0x00000002L
  85. #define STGM_SHARE_EXCLUSIVE  0x00000010L
  86. #define STGM_SHARE_DENY_WRITE 0x00000020L
  87. #define STGM_SHARE_DENY_READ  0x00000030L
  88. #define STGM_SHARE_DENY_NONE  0x00000040L
  89. #define STGM_CREATE           0x00001000L
  90. #define STGM_TRANSACTED       0x00010000L
  91. #define STGM_CONVERT          0x00020000L
  92. #define STGM_PRIORITY         0x00040000L
  93. #define STGM_DELETEONRELEASE  0x04000000L
  94.  
  95. enum STREAM_SEEK {
  96.   STREAM_SEEK_SET = 0,
  97.   STREAM_SEEK_CUR = 1,
  98.   STREAM_SEEK_END = 2
  99. };
  100.  
  101. enum STGC {
  102.   STGC_DEFAULT = 0,
  103.   STGC_OVERWRITE  = 1,
  104.   STGC_ONLYIFCURRENT  = 2,
  105.   STGC_DANGEROUSLYCOMMITMERELYTODISKCACHE = 4
  106. };
  107.  
  108. DEFINE_OLEGUID(IID_IRootStorage, 0x00000012L, 0, 0);    // coguid.h
  109.  
  110. class _ICLASS IStream : public IUnknown {
  111.   public:
  112.     virtual HRESULT _IFUNC Read(void _huge*, uint32, uint32 far*);
  113.     virtual HRESULT _IFUNC Write(void const _huge*, uint32, uint32 far*);
  114.     virtual HRESULT _IFUNC Seek(LARGE_INTEGER, uint32, ULARGE_INTEGER far*);
  115.     virtual HRESULT _IFUNC SetSize(ULARGE_INTEGER);
  116.     virtual HRESULT _IFUNC CopyTo(IStream*, ULARGE_INTEGER, ULARGE_INTEGER far*, ULARGE_INTEGER far*);
  117.     virtual HRESULT _IFUNC Commit(uint32);
  118.     virtual HRESULT _IFUNC Revert();
  119.     virtual HRESULT _IFUNC LockRegion(ULARGE_INTEGER, ULARGE_INTEGER, uint32);
  120.     virtual HRESULT _IFUNC UnlockRegion(ULARGE_INTEGER, ULARGE_INTEGER, uint32);
  121.     virtual HRESULT _IFUNC Stat(STATSTG far*, uint32);
  122.     virtual HRESULT _IFUNC Clone(IStream* far*);
  123. };
  124.  
  125. class _ICLASS IStorage : public IUnknown {
  126.   public:
  127.     virtual HRESULT _IFUNC CreateStream(const char far*, uint32, uint32, uint32, IStream* far*);
  128.     virtual HRESULT _IFUNC OpenStream(const char far*, void far*, uint32, uint32, IStream* far*);
  129.     virtual HRESULT _IFUNC CreateStorage(const char far*, uint32, uint32, uint32, IStorage* far*);
  130.     virtual HRESULT _IFUNC OpenStorage(const char far*, IStorage*, uint32, SNB, uint32, IStorage* far*);
  131.     virtual HRESULT _IFUNC CopyTo(uint32, IID const far*, SNB, IStorage*);
  132.     virtual HRESULT _IFUNC MoveElementTo(char const far*, IStorage*, char const far*, uint32);
  133.     virtual HRESULT _IFUNC Commit(uint32);
  134.     virtual HRESULT _IFUNC Revert();
  135.     virtual HRESULT _IFUNC EnumElements(uint32, void far*, uint32, IEnumSTATSTG* far*);
  136.     virtual HRESULT _IFUNC DestroyElement(const char far*);
  137.     virtual HRESULT _IFUNC RenameElement(const char far*, const char far*);
  138.     virtual HRESULT _IFUNC SetElementTimes(const char far*, FILETIME const far*, FILETIME const far*, FILETIME const far*);
  139.     virtual HRESULT _IFUNC SetClass(const IID far&);
  140.     virtual HRESULT _IFUNC SetStateBits(uint32, uint32);
  141.     virtual HRESULT _IFUNC Stat(STATSTG far*, uint32);
  142. };
  143.  
  144. class _ICLASS IRootStorage : public IUnknown {
  145.   public:
  146.     virtual HRESULT _IFUNC SwitchToFile(const char far* lpstrFile);
  147. };
  148.  
  149. class _ICLASS ILockBytes : public IUnknown {};  // member functions not called
  150. #endif  // #if !defined(_STORAGE_H_)
  151. #endif  // #if !defined(BI_PLAT_WIN32)
  152.  
  153. #if defined(BI_NAMESPACE)
  154. namespace OCF {
  155. #endif
  156.  
  157. //
  158. // class TOcStream
  159. // ~~~~~ ~~~~~~~~~
  160. class _OCFCLASS TOcStream {
  161.   public:
  162.     TOcStream(TOcStorage& storage, const char far* name, bool create,
  163.               uint32 mode = STGM_READWRITE);
  164.     TOcStream(TOcStream& stream);
  165.     TOcStream(IStream* stream);
  166.    ~TOcStream();
  167.  
  168.     IStream* GetIStream();
  169.  
  170.     HRESULT Read(void HUGE* pv, ulong cb, ulong far* read = 0);
  171.     HRESULT Write(void const HUGE* pv, ulong cb, ulong far* written = 0);
  172.     HRESULT Seek(int64 move, uint32 origin= STREAM_SEEK_SET,
  173.                  uint64 far* newPosition = 0);
  174.     HRESULT SetSize(uint64 newSize);
  175.     HRESULT CopyTo(TOcStream& stream, uint64 cb, uint64 far* read = 0,
  176.                    uint64 far* written = 0);
  177.     HRESULT Commit(uint32 commitFlags);
  178.     HRESULT Revert();
  179.     HRESULT LockRegion(uint64 offset, uint64 cb, uint32 lockType);
  180.     HRESULT UnlockRegion(uint64 offset, uint64 cb, uint32 lockType);
  181.     HRESULT Stat(STATSTG far* statstg, uint32 statFlag);
  182.  
  183.   protected:
  184.     HRESULT Clone(IStream far* far* ppstm);
  185.  
  186.     IStream* StreamI;
  187. };
  188.  
  189. //
  190. // class TOcStorage
  191. // ~~~~~ ~~~~~~~~~~
  192. class _OCFCLASS TOcStorage {
  193.   public:
  194.     TOcStorage(const char far* fileName, bool create,
  195.                uint32 mode = STGM_READWRITE|STGM_TRANSACTED);
  196.     TOcStorage(ILockBytes far* lkbyt, bool create,
  197.                uint32 mode = STGM_READWRITE|STGM_TRANSACTED);
  198.     TOcStorage(TOcStorage& parent, const char far* name, bool create,
  199.                uint32 mode = STGM_READWRITE);
  200.     TOcStorage(IStorage* storage);
  201.    ~TOcStorage();
  202.  
  203.     IStorage* GetIStorage();
  204.  
  205.     HRESULT CopyTo(uint32 ciidExclude, IID const far* rgiidExclude,
  206.                    SNB snbExclude, TOcStorage& dest);
  207.     HRESULT MoveElementTo(char const far* name, TOcStorage& dest,
  208.                           char const far* newName, uint32 grfFlags);
  209.     HRESULT Commit(uint32 grfCommitFlags);
  210.     HRESULT Revert();
  211.     HRESULT EnumElements(uint32 reserved1, void far* reserved2,
  212.                          uint32 reserved3, IEnumSTATSTG far*far* ppenm);
  213.     HRESULT DestroyElement(const char far* name);
  214.     HRESULT RenameElement(const char far* oldName, const char far* newName);
  215.     HRESULT SetElementTimes(const char far* name, FILETIME const far* pctime,
  216.                             FILETIME const far* patime,
  217.                             FILETIME const far* pmtime);
  218.     HRESULT SetClass(const IID far& clsid);
  219.     HRESULT SetStateBits(uint32 grfStateBits, uint32 grfMask);
  220.     HRESULT Stat(STATSTG far *pstatstg, uint32 grfStatFlag);
  221.  
  222.     HRESULT SwitchToFile(const char far* newPath);
  223.  
  224.     static HRESULT IsStorageFile(const char far* pwcsName);
  225.     static HRESULT IsStorageILockBytes(ILockBytes far* plkbyt);
  226.     static HRESULT SetTimes(char const far* lpszName,
  227.                             FILETIME const far* pctime,
  228.                             FILETIME const far* patime,
  229.                             FILETIME const far* pmtime);
  230.  
  231.   protected:
  232.     HRESULT CreateStream(const char far* name, uint32 mode, uint32 rsrvd1,
  233.                          uint32 rsrvd2, IStream far* far* stream);
  234.     HRESULT OpenStream(const char far* name, void far *rsrvd1, uint32 grfMode,
  235.                        uint32 rsrvd2, IStream far *far *stream);
  236.     HRESULT CreateStorage(const char far* name, uint32 mode, uint32 rsrvd1,
  237.                           uint32 rsrvd2, IStorage far*far* storage);
  238.     HRESULT OpenStorage(const char far* name, IStorage far* stgPriority,
  239.                         uint32 mode, SNB snbExclude, uint32 rsrvd,
  240.                         IStorage far*far* storage);
  241.     ulong   AddRef();
  242.     ulong   Release();
  243.  
  244. #if 0  // not currently implemented
  245. //    TOcStorage*    GetParent() const {return Parent;}
  246. //    int            GetOpenMode() const {return OpenMode;}
  247. //    void           SetOpenMode(int mode) const {OpenMode = mode;}
  248.  
  249.   protected:
  250. //    int         ThisOpen;     // actual mode bits used for opening storage
  251.  
  252.   private:
  253. //    int         OpenMode;     // mode and protection flags
  254. //    int         OpenCount;
  255. //    TOcStorage* Parent;
  256. #endif
  257.     IStorage*   StorageI;
  258.  
  259.   friend TOcStream;
  260. };
  261.  
  262. #if defined(BI_NAMESPACE)
  263. } // namespace OCF
  264. #endif
  265.  
  266. #endif  // OCF_OCSTORAG_H
  267.